/**
 * @Author: zc
 * @Date: 2019-11-26 10:17:15
 * @LastEditors: zc
 * @LastEditTime: 2020-05-27 16:47:08
 */

import Api from './request';
import Config from './config';
import { omit } from '@/common/utils';

interface Obj {
  name: string;
  method: string;
  path: string;
  isNeedAllData?: boolean; // 是否需要接口返回的所有数据{code, data, msg
}

const Request = (config?: any) => {
  const actions: any = {};
  const _config = Config.concat(config);
  _config.map((item: Obj) => {
    if (!item) return null;
    actions[item.name] = (param: any = {}) => {
      return Api.Request(item.method, item.path, {
        param,
        ...(omit(item, ['method', 'path']) || {})
      });
    };
    return null;
  });
  return actions;
};

export default Request;
